﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 测量大师
{
    public partial class 计算小工具 : Form
    {
        public 计算小工具()
        {
            InitializeComponent();
        }

        private void 计算小工具_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void 弧度转角度_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {

        }

        private void label10_Click(object sender, EventArgs e)
        {

        }

        private void 角度弧度转换_Click(object sender, EventArgs e)
        {
            try
            {
                if(角度转弧度.Checked==true)
                    textBox2.Text = Convert.ToString(Angle.dmstorad(textBox1.Text));
            }
            catch (Exception)
            {

                MessageBox.Show("转折角输入有误，请检查角度的输入是否为° ' '' 格式");
            }

            if (弧度转角度.Checked == true)
                textBox2.Text = Angle.radtodms(double.Parse(textBox1.Text));

        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox9.Text = Angle.radtodms(Math.PI / 2 - Math.Atan2((double.Parse(y2.Text) - double.Parse(y1.Text)), (double.Parse(x2.Text) - double.Parse(x1.Text))));
        }

        private void 点到直线的距离_Click(object sender, EventArgs e)
        {
            double x1, x2, y1, y2;
            x1 = double.Parse(X.Text);
            x2 = (double.Parse(Y.Text) - double.Parse(B.Text)) / double.Parse(K.Text);
            y1 = double.Parse(K.Text) * double.Parse(X.Text) + double.Parse(B.Text);
            y2 = double.Parse(Y.Text);
            double s = Math.Abs(y2 - y1) / Math.Sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1)) * Math.Abs(x2 - x1);
            textBox6.Text = Convert.ToString(s);
        }

        private void 回到主页ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
